package com.cloudbroker.bcs.csvc.base.api.util;

import java.util.Map;

public class HSBCCSUtil {
    
    public static interface ErrorNoReader {
        
        public String getErrorNo(Map<String, Object> result);
        
    }
    
    public static boolean isSuccess(Map<String, Object> result, ErrorNoReader errorNoReader, String successCode) {
        if (null == result) {
            return false;
        }
        String errorNo = errorNoReader.getErrorNo(result);
        return null == errorNo || errorNo.equals(successCode);
    }
    
    public static boolean isErrorOf(Map<String, Object> result, ErrorNoReader errorNoReader, String errorNo) {
        if (null != result) {
            String existsErrorNo = errorNoReader.getErrorNo(result);
            if (null != existsErrorNo) {
                return existsErrorNo.equals(errorNo);
            }
        }
        return false;
    }
    
    public static boolean isErrorIn(Map<String, Object> result, ErrorNoReader errorNoReader, String... errorNos) {
        if (null != result && null != errorNos && 0 < errorNos.length) {
            String existsErrorNo = errorNoReader.getErrorNo(result);
            for (String errorNo : errorNos) {
                if (null != errorNo && errorNo.equals(existsErrorNo)) {
                    return true;
                }
            }
        }
        return false;
    }
    
    public static boolean isErrorIn(String existsErrorNo, String... errorNos) {
        if (null != existsErrorNo && !existsErrorNo.trim().isEmpty() && null != errorNos && 0 < errorNos.length) {
            for (String errorNo : errorNos) {
                if (null != errorNo && errorNo.equals(existsErrorNo)) {
                    return true;
                }
            }
        }
        return false;
    }
    
}
